package com.ustb.springboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ustb.springboot.common.utils.R;
import com.ustb.springboot.common.utils.TokenUtil;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.ustb.springboot.dao.QuestionDatetimeDao;
import com.ustb.springboot.entity.QuestionDatetimeEntity;
import com.ustb.springboot.service.QuestionDatetimeService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;


@Service("questionDatetimeService")
public class QuestionDatetimeServiceImpl extends ServiceImpl<QuestionDatetimeDao, QuestionDatetimeEntity> implements QuestionDatetimeService {
    @Resource
    private QuestionDatetimeDao questionDatetimeDao;

    @Override
    public R delete(Map<String, Object> body) {
        QueryWrapper<QuestionDatetimeEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", body.get("id"));
       return 1 == questionDatetimeDao.delete(queryWrapper) ? R.ok(20000, "删除成功！") : R.error(2000, "删除失败！");
    }

    @Override
    public R save(HttpServletRequest request, QuestionDatetimeEntity questionDatetime) {
        questionDatetime.setUserId(TokenUtil.getId(request));
        return this.save(questionDatetime) ? R.ok(20000, "创建填空题成功！") : R.error(2000, "创建失败！");
    }

    @Override
    public List<QuestionDatetimeEntity> queryQuestionDatetimeEntity(Map<String, Object> body) {
        QueryWrapper<QuestionDatetimeEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", body.get("question_id"));
        return questionDatetimeDao.selectList(queryWrapper);
    }
}